package com.shxzz.easy12306.services.ticket.toolkit;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.Period;

/**
 * 日期工具类
 * @author shxzz
 * @create 2024-03-05-20:01
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DateUtil {

    /**
     * 计算时间差，格式化返回
     */
    public static String formatTimeDifference(LocalDateTime startTime, LocalDateTime endTime) {
        Duration between = Duration.between(startTime, endTime);
        return String.format("%02d:%02d", between.toHours(), between.toMinutes() % 60);
    }

    public static Integer getDaysBetween(LocalDateTime startTime, LocalDateTime endTime) {
        return Period.between(startTime.toLocalDate(), endTime.toLocalDate()).getDays();
    }

}
